package GUI;

import java.util.ArrayList;
import java.util.List;

import org.newdawn.slick.Graphics;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.geom.Vector2f;

import Game.GameHelper;
import Tools.Drawing.FontTagSystem;
import Tools.Drawing.FontTagSystem.EAlign;

/** GUI Messenger class
 * @author Aikidos
 */
public class GuiMessenger {
	
	private List<String> _lstMessages = new ArrayList<String>();
	
	private int _timerUp = 3000;
	private int _maxMessages = 4;
	
	public Vector2f Position;
	public float DrawOffset = 20.f;
	
	public GuiMessenger() throws SlickException {
		Position = new Vector2f(GameHelper.getGame().getWidth() / 2,
				GameHelper.getGame().getHeight() - 100);
	}
	
	/** Add new message
	 * @param message - Message
	 */
	public void addMessage(String message) {
		_lstMessages.add(message);
		
		if (_lstMessages.size() > _maxMessages) _lstMessages.remove(0);
	}
	
	/** Update messenger
	 * @param delta - Time delta
	 */
	public void update(int delta) {
		if (_lstMessages.size() > 0) {
			if (_timerUp <= 0) {
				_lstMessages.remove(0);

				_timerUp = 3000;
			} else
				_timerUp -= delta;
		} else 
			_timerUp = 3000;
	}
	
	/** Draw all messages
	 * @param g - Slick2d graphics
	 */
	public void draw(Graphics g) {	
		Vector2f drawPos = new Vector2f();
		drawPos.set(Position);
		
		for (String message : _lstMessages) {
			FontTagSystem.drawText(message, drawPos, EAlign.CENTER);
			drawPos.y += DrawOffset;
		}
	}
	
}
